//============================================================================
// Name        : ArithmeticEncoding.cpp
// Author      : Rushi
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
class SymbolFrequency {
public:
  char symbol;
  float frequency;
  SymbolFrequency(char symbol, float frequency) {
    this->symbol = symbol;
    this->frequency = frequency;
  }
};
SymbolFrequency givenSymbols[] = { SymbolFrequency('-', 0.0), SymbolFrequency('M', 0.4), SymbolFrequency('U', 0.6), SymbolFrequency('X', 0.9), SymbolFrequency('Y', 1) };
SymbolFrequency inputSymbols[] = { SymbolFrequency('M', 0.4), SymbolFrequency('U', 0.2), SymbolFrequency('M', 0.4), SymbolFrequency('M', 0.4), SymbolFrequency('Y', 0.1) };
float high = 1.0;
float low = 0.0;
int main() {
  int totalSymbols = 5;
  int symbolIndex;
  for (int i = 0; i < totalSymbols; i++) {
    char currentCharacter = inputSymbols[i].symbol;
    for (symbolIndex = 0; symbolIndex < totalSymbols; symbolIndex++) {
      if (currentCharacter == givenSymbols[symbolIndex].symbol)
        break;
    }
    float codeRange = high - low;
    high = low + (codeRange * (givenSymbols[symbolIndex].frequency));
    low = low + (codeRange * (givenSymbols[symbolIndex - 1].frequency));
  }

  float tagValue = (high + low) / 2;
string outputString = "";
do{
for(symbolIndex = 1; symbolIndex < totalSymbols; symbolIndex++) {
  if((tagValue < givenSymbols[symbolIndex].frequency) && (tagValue > givenSymbols[symbolIndex-1].frequency)) {
    outputString += givenSymbols[symbolIndex].symbol;
    break;
  }

}
if(tagValue > 0.95) break;
tagValue = fabs((tagValue-givenSymbols[symbolIndex-1].frequency))/fabs((givenSymbols[symbolIndex].frequency-givenSymbols[symbolIndex-1].frequency));
}while(1);
printf("%s",outputString.c_str());
return 0;
}
